"""
应用KNN算法对鸢尾花数据集进行训练，
要求：训练时要求只使用花萼长度和花萼宽度两个特征，输出训练集和测试集的得分。（分值：15；结果：截图呈现图片命令为图3；代码命名2.py）
"""
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier as KNN

iris = load_iris()
x_train, x_test, y_train, y_test = train_test_split(
    iris.data[:, :2], iris.target)
model = KNN()
model.fit(x_train, y_train)
train_score = model.score(x_train, y_train)
test_score = model.score(x_test, y_test)
print(f'训练得分:{train_score:.2f}')
print(f'测试得分:{test_score:.2f}')
